<template>
  <div class="login">
    <div class="login-box">
      <h2 style="font-size: 30px;margin-bottom:30px">扫码点餐商户端</h2>
      <el-form
        :label-position="labelPosition"
        label-width="80px"
        :model="loginForm"
        ref="loginRef"
        :rules="rules"
      >
        <el-form-item label="账号" prop="account">
          <el-input v-model="loginForm.account"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="loginForm.password" show-password></el-input>
        </el-form-item>
        <div class="login-bottom">
          <el-button type="success" style="width: 200px" @click="loginbtn"
            >登录</el-button
          >
          <div class="zc-btn">注册</div>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex';
export default {
  data() {
    return {
      labelPosition: "right",
      loginForm: {
        account: "17600000000",
        password: "s123456",
      },
      rules: {
        account: [
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "手机号格式不正确",
            trigger: "blur",
          },
        ],
        password: [
          {
            min: 6,
            max: 10,
            message: "密码格式不正确",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    ...mapActions('my_user',['loginAsync']),
    //   登录按钮
    loginbtn() {
      this.$refs["loginRef"].validate(async isok => {
        if (isok) {
          await this.loginAsync(this.loginForm)
          this.$router.push("/Layout");
          this.$message.success();
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.login {
  width: 100vw;
  height: 100vh;
  background-color: pink;
  position: relative;
}
.login-box {
  width: 570px;
  height: 350px;
  background-color: rgba(242, 221, 140);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  box-sizing: border-box;
  padding: 20px 30px;
  text-align: center;
}
.login-bottom {
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
}
.login-bottom .el-button {
  margin-left: 144px;
  margin-top: 30px;
}
.zc-btn {
  font-weight: 700;
}
.el-form-item__label {
  font-weight: 900;
}
</style>
